package com.xzc.lease.web.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xzc.lease.model.entity.ApartmentInfo;
import com.xzc.lease.model.entity.FacilityInfo;
import com.xzc.lease.model.entity.LabelInfo;
import com.xzc.lease.model.enums.ItemType;
import com.xzc.lease.web.app.mapper.*;
import com.xzc.lease.web.app.service.ApartmentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xzc.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.xzc.lease.web.app.vo.apartment.ApartmentItemVo;
import com.xzc.lease.web.app.vo.graph.GraphVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 徐生
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    private LabelInfoMapper labelInfoMapper;
    @Autowired
    private GraphInfoMapper graphInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private FacilityInfoMapper facilityInfoMapper;

    /**
     * 根据id查询公寓信息
     *
     * @param apartmentId
     * @return
     */
    public ApartmentItemVo selectApartmentItemVoById(Long apartmentId) {
        //查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);

        //1、根据apartmentId查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(apartmentId);
        //2、根据apartmentId查询图片信息
        List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, apartmentId);
        //3、根据apartmentId查询最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(apartmentId);

        //组装条件返回
        ApartmentItemVo apartmentItemVo = new ApartmentItemVo();
        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);
        apartmentItemVo.setGraphVoList(graphVoList);
        apartmentItemVo.setLabelInfoList(labelInfoList);
        apartmentItemVo.setMinRent(minRent);
        return apartmentItemVo;
    }

    /**
     * 根据id获取详细公寓信息
     *
     * @param apartmentId
     * @return
     */
    public ApartmentDetailVo getDetailById(Long apartmentId) {
        //查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);

        //1、根据apartmentId查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(apartmentId);
        //2、根据apartmentId查询图片信息
        List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, apartmentId);
        //3、根据apartmentId查询配套信息
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectListByApartmentId(apartmentId);
        //4、根据apartmentId查询最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(apartmentId);

        //组装条件返回
        ApartmentDetailVo apartmentItemVo = new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);
        apartmentItemVo.setGraphVoList(graphVoList);
        apartmentItemVo.setLabelInfoList(labelInfoList);
        apartmentItemVo.setFacilityInfoList(facilityInfoList);
        apartmentItemVo.setMinRent(minRent);
        return apartmentItemVo;
    }
}




